package work.xiaohong.autocode;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Arrays;
import java.util.Collections;

public class Application {

    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/811wms?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true","root", "root")
//        FastAutoGenerator.create("jdbc:mysql://192.168.2.215:3306/811wms?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true","Sido1", "Sido2023$")
//        FastAutoGenerator.create("jdbc:mysql://42.193.246.110:3070/xiaohong-wms?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true","root", "xiaohongsql")
//        FastAutoGenerator.create("jdbc:postgresql://wms.xiaohong.work:5432/xiaohong-wms?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true","postgres", "xiaohongsql")
                .globalConfig(builder -> {
                    builder.author("陈鸿") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .disableOpenDir() // 禁止打开输出目录
                            .commentDate("yyyy-MM-dd HH:mm:ss") //注释日期格式
                            .outputDir(System.getProperty("user.dir")+"\\src\\main\\java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("cn.sidonn") // 设置父包名
                            .moduleName("wms") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, System.getProperty("user.dir")+"\\src\\main\\resources\\mapper")); // 设置mapperXml生成路径
                })
                .templateConfig(builder -> {
                    builder.disable()
                            .entity("/templates/entity.java")
                            .service("/templates/service.java")
                            .serviceImpl("/templates/serviceImpl.java")
                            .mapper("/templates/mapper.java")
                            .mapperXml("/templates/mapper.xml")
                            .controller("/templates/controller.java");
                })
                .strategyConfig(builder -> {
                    builder
//                            .addInclude("test_first","test_second") // 设置需要生成的表名
                            .addTablePrefix("wms_") // 设置过滤表前缀
                            .mapperBuilder()
                            .enableMapperAnnotation()
                            .entityBuilder()
                            .disableSerialVersionUID()
                            .enableLombok()
                            .enableTableFieldAnnotation()
                            .versionColumnName("version") //乐观锁字段名(数据库)
                            .versionPropertyName("version") //乐观锁字段名(数据库)
                            .logicDeleteColumnName("deleted")	//逻辑删除字段名(数据库)
                            .logicDeletePropertyName("deleted")	//逻辑删除属性名(实体)
                            .addTableFills(new Column("gmt_create", FieldFill.INSERT)) // 添加表字段填充
                            .addTableFills(new Column("gmt_modified", FieldFill.INSERT_UPDATE)) //添加表字段填充
                            .idType(IdType.AUTO); //全局主键类型
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }

}
